package 
{
	import assets.EmbededAssets;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import game.ApplicationFacade;
	import game.utils.sort.Radix;
	import game.view.screen.ApplicationScreen;
	import starling.core.Starling;
	
	/**
	 * ...
	 * @author Thot
	 */
	public class Main extends Sprite 
	{
		private var _starling:Starling;
		
		public function Main():void 
		{
			addEventListener(Event.ADDED_TO_STAGE, stage2DHandler);
		}
		
		private function stage2DHandler(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, stage2DHandler);
			
			stage.scaleMode = StageScaleMode.SHOW_ALL;
            stage.align = StageAlign.TOP_LEFT;
			
			Starling.multitouchEnabled = true; // useful on mobile devices
            Starling.handleLostContext = true; // deactivate on mobile devices (to save memory)
			
			_starling = new Starling(ApplicationScreen, stage);
            _starling.simulateMultitouch = true;
            _starling.enableErrorChecking = false;
            _starling.start();
            
            // this event is dispatched when stage3D is set up
            _starling.stage3D.addEventListener(Event.CONTEXT3D_CREATE, stage3DHandler);
		}
		
		private function stage3DHandler(e:Event):void 
		{
			if (Starling.context.driverInfo.toLowerCase().indexOf("software") != -1)
			{
                Starling.current.nativeStage.frameRate = 30;
				trace("software mode");
			}
			
			ApplicationFacade.getInstance().startApp();
		}
		
	}
	
}